package com.ygqh.baby.po;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.JSON;
import com.ygqh.baby.ao.DataStatus;
import com.ygqh.baby.utils.WebUtils;

public class ScheduleJob implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Long id;

	private String jobGroup;

	private String jobName;

	private String jobStatus;

	private String jobType;

	private String ipAddr;

	private Integer jobNum;

	private String cron;

	private Date cronDate;

	private String description;

	private String isConcurrent;

	private String beanClass;

	private String springId;

	private String methodName;

	private String data;

	private Date createTime;

	private String createBy;

	private Date updateTime;

	private String updateBy;

	private DataStatus status;

	@SuppressWarnings("unchecked")
	public Map<String, Object> getDataMap() {
		Map<String, Object> dataMap = null;
		if (StringUtils.isNotBlank(data)) {
			dataMap = JSON.parseObject(data, LinkedHashMap.class);
		}
		return dataMap;
	}

	public ScheduleJob() {
		super();
	}

	public ScheduleJob(String jobGroup, String jobName, String jobStatus, String jobType, Integer jobNum, String cron, String description, String isConcurrent,
			String beanClass, String springId, String methodName, String data) {
		super();
		this.jobGroup = jobGroup;
		this.jobName = jobName;
		this.jobStatus = jobStatus;
		this.jobType = jobType;
		this.jobNum = jobNum;
		this.cron = cron;
		this.description = description;
		this.isConcurrent = isConcurrent;
		this.beanClass = beanClass;
		this.springId = springId;
		this.methodName = methodName;
		this.data = data;
		this.ipAddr = WebUtils.getLocalIpAddr();
	}

	public Date getCronDate() {
		return cronDate;
	}

	public void setCronDate(Date cronDate) {
		this.cronDate = cronDate;
	}

	public String getIpAddr() {
		return ipAddr;
	}

	public void setIpAddr(String ipAddr) {
		this.ipAddr = ipAddr;
	}

	public Long getId() {
		return id;
	}

	public DataStatus getStatus() {
		return status;
	}

	public void setStatus(DataStatus status) {
		this.status = status;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getJobGroup() {
		return jobGroup;
	}

	public void setJobGroup(String jobGroup) {
		this.jobGroup = jobGroup == null ? null : jobGroup.trim();
	}

	public String getJobName() {
		return jobName;
	}

	public void setJobName(String jobName) {
		this.jobName = jobName == null ? null : jobName.trim();
	}

	public String getJobStatus() {
		return jobStatus;
	}

	public void setJobStatus(String jobStatus) {
		this.jobStatus = jobStatus == null ? null : jobStatus.trim();
	}

	public String getJobType() {
		return jobType;
	}

	public void setJobType(String jobType) {
		this.jobType = jobType == null ? null : jobType.trim();
	}

	public Integer getJobNum() {
		return jobNum;
	}

	public void setJobNum(Integer jobNum) {
		this.jobNum = jobNum;
	}

	public String getCron() {
		return cron;
	}

	public void setCron(String cron) {
		this.cron = cron == null ? null : cron.trim();
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description == null ? null : description.trim();
	}

	public String getIsConcurrent() {
		return isConcurrent;
	}

	public void setIsConcurrent(String isConcurrent) {
		this.isConcurrent = isConcurrent == null ? null : isConcurrent.trim();
	}

	public String getBeanClass() {
		return beanClass;
	}

	public void setBeanClass(String beanClass) {
		this.beanClass = beanClass == null ? null : beanClass.trim();
	}

	public String getSpringId() {
		return springId;
	}

	public void setSpringId(String springId) {
		this.springId = springId == null ? null : springId.trim();
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName == null ? null : methodName.trim();
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data == null ? null : data.trim();
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy == null ? null : createBy.trim();
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy == null ? null : updateBy.trim();
	}

	public Boolean isCornValid() {
		if (StringUtils.isEmpty(cron)) {
			return false;
		}
		try {
			SimpleDateFormat dateFormat = new SimpleDateFormat("ss mm HH dd MM ? yyyy");
			Date parse = dateFormat.parse(cron);
			if (parse != null && new Date().after(parse)) {
				return false;
			}
		} catch (Exception e) {
		}
		return true;

	}
}